package com.ocom.payconfig.controller;

import com.ocom.common.constant.PayConfigUrl;
import com.ocom.common.entity.card.EntityXfAccountInfo;
import com.ocom.common.entity.human.EntityPersonnelInfo;
import com.ocom.common.enums.ResultEnum;
import com.ocom.common.request.payconfig.NotMealRequest;
import com.ocom.common.resp.Result;
import com.ocom.common.utils.ResultUtil;
import com.ocom.common.vo.ccb.CcbzhshAddUserVo;
import com.ocom.common.vo.human.GetPersonAndAccountVo;
import com.ocom.payconfig.service.PersonnelInfoService;
import com.ocom.payconfig.service.XfAccountInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@RestController
public class PersonnelInfoController {

    @Autowired
    private PersonnelInfoService personnelInfoService;

    @Autowired
    private XfAccountInfoService xfAccountInfoService;

    @PostMapping(PayConfigUrl.URLP_getOnePersonInfo)
    public Result getPageChannel(Long comId, String pCode,String pName){

        if (comId ==null || pCode==null || pName==null){
            return ResultUtil.error(ResultEnum.Err_203);
        }

        EntityPersonnelInfo entityPersonnelInfo=personnelInfoService.getOnePersonInfo(comId, pCode,pName);
        if (entityPersonnelInfo==null){
            return ResultUtil.error(ResultEnum.Err_4017);
        }
        if (entityPersonnelInfo.getStatus()!=0){
            return ResultUtil.error(ResultEnum.Err_4023);
        }
        EntityXfAccountInfo entityXfAccountInfo=xfAccountInfoService.GetXFAccount(comId, Math.toIntExact(entityPersonnelInfo.getPId()),0);
        if (entityXfAccountInfo==null){
            return ResultUtil.error(ResultEnum.Err_816);
        }
        Map<String,Object> map=new HashMap<>();
        map.put("comId",comId);
        map.put("pCode",pCode);
        map.put("pName",pName);
        map.put("pId",entityPersonnelInfo.getPId());
        map.put("accountRechargeMoney",entityXfAccountInfo.getAccountRechargeMoney());
        return ResultUtil.success(map);
    }

    @PostMapping(PayConfigUrl.URLP_getOnePersonInfoBypId)
    public Result getOnePersonInfo(@RequestBody CcbzhshAddUserVo request){
        EntityPersonnelInfo entityPersonnelInfo = personnelInfoService.getOnePersonInfo(request.getComId(),request.getPId());
        return ResultUtil.success(entityPersonnelInfo);
    }


    @PostMapping(PayConfigUrl.URLP_getPersonAndAccount)
    public Result getPersonAndAccount(@RequestBody GetPersonAndAccountVo request){
        return ResultUtil.success(personnelInfoService.selectPersonAndAccount(request.getComId(), request.getAccType(), request.getDeptIdList(), request.getPTags()));
    }


    @PostMapping(PayConfigUrl.URL_getMealPerReports)
    public Result getMealPerReports(@RequestBody NotMealRequest request){
        return ResultUtil.success(personnelInfoService.getMealPerReports(request.getComId(), request));
    }

}
